<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="内容详情"></uni-navbar></view>

		<view class="detail-info" v-show="willInfo.id">
			<view class="form-box form-box-show">
				<u-form>
					<u-form-item class="form-item" label="提交人">
						<!-- block -->
						<view class="input-text">{{ willInfo.createBy }}</view>
					</u-form-item>

					<u-form-item class="form-item" label="手机号码">
						<!-- block -->
						<view class="input-text">{{ willInfo.phone }}</view>
					</u-form-item>
					<u-form-item class="form-item" label="问题地点">
						<!-- block -->
						<view class="input-text">{{ willInfo.questionPlace }}</view>
					</u-form-item>
					<u-form-item class="form-item" label="提交时间">
						<!-- block -->
						<view class="input-text">{{ willInfo.submitTime }}</view>
					</u-form-item>
					<u-form-item class="form-item" label="问题标题">
						<!-- block -->
						<view class="input-text">{{ willInfo.questionTitle }}</view>
					</u-form-item>
					<u-form-item class="form-item" label="正文内容" label-position="top">
						<!-- block -->
						<view class="text-l" v-html="willInfo.content"></view>
					</u-form-item>
				</u-form>
			</view>
		</view>

		<!-- <view class="uploader-add" @click="onTts">
			<image v-if="!play" src="/static/img/icon_76.png" mode="widthFix"></image>
			<image src="/static/img/icon_77.gif" v-else mode="widthFix"></image>
		</view> -->

		<view class="file-list" v-if="fileList2.length > 0">
			<view>附件:</view>
			<view class="file-item" v-for="(item, index) in fileList2" :key="index" @click="$showLine(item)">
				<view class="file-name clamp">{{ item.name }}</view>
				<view class="right-type">预览</view>
			</view>
		</view>

		<block v-if="willInfo.nodeStatus == 1 && $sysBtns('db_shenhe')">
			<view class="com-h2"><text class="text">问题审核</text></view>
			<view class="form-box">
				<u-form :model="form">
					<u-form-item class="form-item" required label="审核类型" label-width="150" prop="type">
						<u-radio-group v-model="type" @change="typeGroupChange" :key="type">
							<u-radio v-for="(item, index) in typeList" :key="index" :name="item.name" width="260">{{ item.label }}</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item class="form-item" label="处理结果" label-position="top">
						<!-- block -->
						<u-input inputAlign="left" v-model="form.opinion" type="textarea" placeholder="请输入处理结果" :clearable="false" :height="160" :maxlength="-1" />
					</u-form-item>
					<u-form-item class="form-item " label="" label-width="0">
						<!-- block -->
						<uni-file-upload :type="['all', 'image', 'audio']" :limit="10"></uni-file-upload>
					</u-form-item>
				</u-form>
			</view>

			<view class="fiexd-btm"><u-button class="form-btn" type="error" @click="confirm">提交</u-button></view>
		</block>

		<block v-if="willInfo.nodeStatus > 1">
			<view class="com-h2"><text class="text">问题审核</text></view>
			<view class="form-box form-box-show">
				<u-form>
					<u-form-item class="form-item" label="审核意见">
						<view>{{ willInfo.processTypeValue }}</view>
					</u-form-item>

					<u-form-item class="form-item" label="审核时间">
						<view>{{ willInfo.processTimeStr }}</view>
					</u-form-item>
				</u-form>
			</view>
		</block>

		<block v-if="willInfo.nodeStatus > 1">
			<view class="com-h2"><text class="text">问题办理</text></view>
			<view class="form-box form-box-show">
				<u-form>
					<u-form-item class="form-item" label="办理状态">
						<view>{{ willInfo.nodeStatusValue }}</view>
					</u-form-item>

					<u-form-item class="form-item" label="处理结果" label-position="top" v-if="willInfo.processType == 1">
						<!-- block -->
						<view class="text-l" v-html="willInfo.toBeReviewedIdea"></view>
					</u-form-item>
					<view class="file-list" v-if="fileList1.length > 0 && willInfo.processType == 1">
						<view>附件:</view>
						<view class="file-item" v-for="(item, index) in fileList1" :key="index" @click="$showLine(item)">
							<view class="file-name clamp">{{ item.name }}</view>
							<view class="right-type">预览</view>
						</view>
					</view>
				</u-form>
			</view>
		</block>

		<block v-if="willInfo.nodeStatus > 2 && willInfo.processType == 1">
			<view class="com-h2"><text class="text">问题待办结</text></view>
			<view class="form-box form-box-show">
				<u-form>
					<u-form-item class="form-item" label="办理结果" label-position="top">
						<view class="text-l">{{ willInfo.shfwzlzxResult }}</view>
					</u-form-item>
					<view class="file-list" v-if="fileList3.length > 0">
						<view>附件:</view>
						<view class="file-item" v-for="(item, index) in fileList3" :key="index" @click="$showLine(item)">
							<view class="file-name clamp">{{ item.name }}</view>
							<view class="right-type">预览</view>
						</view>
					</view>

					<u-form-item class="form-item" label="办理时间">
						<view>{{ willInfo.shfwzlzxTimeStr }}</view>
					</u-form-item>
					<u-form-item class="form-item" label="审核意见" v-if="willInfo.nodeStatus > 3">
						<view>{{ `通过` }}</view>
					</u-form-item>
				</u-form>
			</view>
		</block>

		<block v-if="willInfo.nodeStatus == 3 && $sysBtns('db_banjie')">
			<view class="form-box">
				<u-form :model="form1">
					<u-form-item class="form-item" required label="办理审核" label-width="150" prop="pass">
						<u-radio-group v-model="pass" @change="passGroupChange" :key="pass">
							<u-radio v-for="(item, index) in passList" :key="index" :name="item.name" width="260">{{ item.label }}</u-radio>
						</u-radio-group>
					</u-form-item>
				</u-form>
			</view>

			<view class="fiexd-btm"><u-button class="form-btn" type="error" @click="confirm2">确认</u-button></view>
		</block>

		<block v-if="willInfo.nodeStatus == 4">
			<view class="com-h2"><text class="text">问题办结</text></view>
			<view class="form-box form-box-show">
				<u-form>
					<u-form-item class="form-item" label="办结人">
						<view>{{ willInfo.endName }}</view>
					</u-form-item>

					<u-form-item class="form-item" label="办结时间">
						<view>{{ willInfo.endTimeStr }}</view>
					</u-form-item>

					<u-form-item class="form-item" label="处理结果" label-position="top">
						<!-- block -->
						<view class="text-l" v-html="willInfo.toBeReviewedIdea"></view>
					</u-form-item>
					<view class="file-list" v-if="fileList1.length > 0">
						<view>附件:</view>
						<view class="file-item" v-for="(item, index) in fileList1" :key="index" @click="$showLine(item)">
							<view class="file-name clamp">{{ item.name }}</view>
							<view class="right-type">预览</view>
						</view>
					</view>
				</u-form>
			</view>
		</block>

		<view v-if="false"></view>
	</view>
</template>

<script>
import uniFileUpload from '@/components/uni-file-uploader.vue';
import uniParse from '@/components/uni-parse/parse.vue';
import selectTree from '@/components/uni-select-tree.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniFileUpload,
		uniParse,
		selectTree
	},
	data() {
		return {
			statusMap: {
				0: '所有',
				1: '待审核',
				2: '办理中',
				3: '已答复',
				4: '已办结',
				5: '不予受理'
			},

			type: '',
			typeShow: false,
			typeList: [],

			pass: '',
			passShow: false,
			passList: [
				{
					name: 1,
					value: 1,
					label: '通过'
				},
				{
					name: 0,
					value: 0,
					label: '退回到社会服务治理中心'
				}
			],

			id: '',
			userId: '',
			status: '1',
			willInfo: {},
			fileList1: [],
			fileList2: [],
			fileList3: [],
			form: {
				type: '',
				opinion: ''
			},
			form1: {
				pass: ''
			},
			rules: {
				type: [
					{
						required: true,
						message: '请选择审核类型',
						trigger: 'change'
					}
				],
				pass: [
					{
						required: true,
						message: '请选择办理意见',
						trigger: 'change'
					}
				],
				opinion: [
					{
						required: true,
						message: '请输入处理结果',
						trigger: 'change'
					}
				]
			},
			key: -1,
			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		if (option.status) {
			this.status = option.status;
		}
		this.loadDict('process_type', 'typeList');

		this.loadData();
	},
	onReady() {
		// this.$refs.uForm.setRules(this.rules);
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
		this.$store.commit('filePush', []);
	},
	computed: {
		...mapState(['userInfo', 'fileList'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');
			} else {
				this.$logout();
			}
		},
		loadDict(type, list, value) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this[list] = [];
				res.data.forEach((item) => {
					this[list].push({
						name: item.dictValue,
						value: item.dictValue,
						label: item.dictName
					});
				});
			});
		},
		loadData() {
			this.$request('/lvzhitong/questions/detail', {
				id: this.id,
				userId: this.userId
			}).then((res) => {
				if (!res.data) {
					this.$msg('暂无数据');
					return false;
				}
				this.fileList1 = res.data.toBeReviewedFile || [];
				this.fileList2 = res.data.submitFile || [];
				this.fileList3 = res.data.elseFile || [];
				this.willInfo = res.data;
			});
		},
		typeConfirm(e) {
			this.type = e[0].label;
			this.form.type = e[0].value;
		},
		typeGroupChange(e) {
			this.type = e;
			this.form.type = e;
		},
		passConfirm(e) {
			this.pass = e[0].label;
			this.form1.pass = e[0].value;
		},
		passGroupChange(e) {
			this.pass = e;
			this.form1.pass = e;
		},
		confirm() {
			let data = {};
			data = {
				userId: this.userId,
				role: this.roleCodes,
				processType: this.form.type,
				toBeReviewedIdea: this.form.opinion,
				id: this.willInfo.id,
				toBeReviewedFile: this.fileList
			};

			if (!data.processType) {
				this.$msg('请选择审核类型');
				return false;
			}

			let url = '/lvzhitong/questions/toBeReviewed';
			this.$request(url, data, {
				load: true
			}).then((res) => {
				this.$msg(res.msg);
				this.navigateBack();
			});
		},
		confirm1() {
			let data = {};
			data = {
				handlingResulst: this.form.idea,
				id: this.willInfo.id
			};

			let url = '/minqingzhitong/msPublicOpinion/stationExamine';
			this.$request(url, data, {
				load: true
			}).then((res) => {
				this.$msg(res.msg);
				this.back();
			});
		},
		confirm2() {
			let data = {};
			data = {
				userId: this.userId,
				role: this.roleCodes,
				isPass: this.form1.pass,
				id: this.willInfo.id
			};

			if (!data.isPass) {
				this.$msg('请输入审核意见');
				return false;
			}

			let url = '/lvzhitong/questions/pendApproval';
			this.$request(url, data, {
				load: true
			}).then((res) => {
				this.$msg(res.msg);
				this.back();
			});
		},
		back(e) {
			this.navigateBack();
		},
		navigateBack(e) {
			setTimeout(() => {
				let pre = this.$prePage();
				if (pre && pre.loadData) {
					pre.loadData('refresh');
				}
				uni.navigateBack();
			}, 500);
		},
		call(e) {
			uni.makePhoneCall({
				phoneNumber: e.phone
			});
		},
		onTts() {
			let text = this.willInfo.questionTitle || '';
			text += '，时间：' + this.willInfo.createTimeStr;
			text += '，联系电话：' + this.willInfo.phone;
			text += '，问题编号：' + this.willInfo.questionCode;
			text += '，发生地点：' + this.willInfo.questionPlace;
			text += '，' + this.willInfo.content;
			this.$tts(text, this, 500);
		},
		previewImage(idx, images) {
			uni.previewImage({
				current: idx,
				urls: images
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.detail-info {
	padding: 0;

	.overflow {
		padding: 20rpx 30rpx 0;
	}
}

.site-box {
	padding: 30rpx 30rpx 0;
	background-color: #f5f7fa;
}

.sched-box {
	padding: 10rpx 50rpx;
}

.form-box {
	.form-item {
		@include mp-flex;
		// border-bottom: 20rpx solid #f5f7fa;

		.input-text {
			padding: 11rpx 0;
			line-height: 48rpx;
			text-align: right;
		}

		.text-l {
			width: 100%;
			white-space: pre-line;
			text-align: left;
		}
	}
}

.filter-box {
	position: fixed;
	left: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
